#!/bin/sh

# Set mdev
echo /sbin/mdev > /proc/sys/kernel/hotplug
/sbin/mdev -s && echo "mdev is ok......"

# networking
ifconfig lo up

mount -t squashfs /dev/mtdblock6 /appfs
mount -t squashfs /dev/mtdblock7 /audio_file
mount -t jffs2 /dev/mtdblock8 /mnt/config

if [ -e "/mnt/config/no_network" ];then
    date -s "2024-01-25 8:00:00"
fi

. /etc/common.env
. /etc/chip.env
. /etc/profile.env
insmod_sdk_modules.sh
read_sensor_id.sh
. /etc/sensor_type.env

if [ -e "/root/dual_sensor" ];then
    insmod /lib/modules/$G_SENSOR_NAME.ko sensor0_switch=1
    echo 18 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio18/direction
    echo 1 > /sys/class/gpio/gpio18/value
else
    insmod /lib/modules/$G_SENSOR_NAME.ko
fi

if [ "$G_SENSOR_NAME" != "no_sensor" ];then
    insmod /lib/modules/ak_venc_adapter.ko
    insmod /lib/modules/ak_venc_bridge.ko
fi

# enable wifi gpio #
echo $G_USB_WIFI_GPIO > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio$G_USB_WIFI_GPIO/direction
echo 0 > /sys/class/gpio/gpio$G_USB_WIFI_GPIO/value

read_wifi_module.sh
. /etc/wifi_type.env

if [ $G_WIFI_MODULE = "atbm6x3x_wifi_usb" ];then
    insmod /lib/modules/$G_WIFI_MODULE.ko wifi_bt_comb=1
else
    insmod /lib/modules/$G_WIFI_MODULE.ko stacfgpath=/etc/ssv6x5x-wifi.cfg
fi

#upload jpg path
mkdir /tmp/tmpfs

echo 100 > /proc/sys/vm/swappiness
echo 8388608 > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon /dev/zram0

#telnetd
telnetd &
sdk_tcp_daemon.sh &

if [ -e "/mnt/config/audio_record_file.pcm" ];then
    size=`stat -c %s /mnt/config/audio_record_file.pcm`
    if [ $size -ge 204800 ];then
        echo "record pcm is too big"
        rm /mnt/config/audio_record_file.pcm
    fi
fi

# Run init script
if [ -f /system/init/app_init.sh ]; then
    /system/init/app_init.sh &
fi
